class Tscn {
    steps = 0;
    fromat = 2;
    extResources: TscnExtResource[];
    subResources: TscnSubResource[];
    nodeRoots: TscnNode[];
    signals: TscnSignal[]

    constructor() {
        this.extResources = [];
        this.subResources = [];
        this.nodeRoots = [];
        this.signals = []
    }

    pushExt(ext: TscnExtResource) {
        this.extResources.push(ext);
    }
    pushSub(sub: TscnSubResource) {
        this.subResources.push(sub)
    }
    pushRootNode(node: TscnNode) {
        this.nodeRoots.push(node)
    }
    pustNodeChildren(parent: TscnNode, child: TscnNode) {
        parent.children.push(child)
    }
    pushSignal(signal: TscnSignal) {
        this.signals.push(signal)
    }
}

class TscnExtResource {
    path: string
    type: string
    id = 1

    constructor(
        path: string,
        type: string,
        id = 1
    ) {
        this.path = path;
        this.type = type
        this.id = id
    }
}

class TscnSubResource {
    type: string
    id = 1
    props: TscnProp[];

    constructor(
        type: string,
        id = 1
    ) {
        this.type = type
        this.id = id
        this.props = [];
    }

    pushProp(prop:TscnProp){
        this.props.push(prop)
    }
}

class TscnNode {
    name: string
    type: string
    parent: string
    attrs: TscnAttr[] = []
    props: TscnProp[] = []
    children: TscnNode[] = [];

    constructor(
        name: string,
        type: string,
        parent: string = ''
    ) {
        this.name = name
        this.type = type
        this.parent = parent
    }

    pushAttr(attr:TscnAttr){
        this.attrs.push(attr)
    }

    pushProp(prop:TscnProp){
        this.props.push(prop)
    }
}

class TscnProp {
    name: string;
    type : string;
    // 将值转换为字符串
    value: string;
    constructor(
        name: string,
        type:string,
        value: string
    ) {
        this.name = name
        this.type = type
        this.value = value
    }
}

class TscnAttr extends TscnProp {

}

class TscnSignal {
    signal: string;
    from: string;
    to: string;
    method: string;

    constructor(
        signal: string,
        from: string,
        to: string,
        method: string
    ) {
        this.signal = signal
        this.from = from
        this.to = to
        this.method = method
    }
}

enum NodeType {
    "SCENE" = 'gd_scene',
    "EXT" = 'ext_resource',
    "SUB" = 'sub_resource',
    'NODE' = 'node',
    'SIGNAL' = 'connection'
}
enum SceneAttrName {
    'STEPS' = 'load_steps',
    'FORMAT' = 'format'
}
enum ExtAttrName {
    'PATH' = 'path',
    "TYPE" = 'type',
    "ID" = 'id'
}
enum SubAttrName {
    "TYPE" = 'type',
    "ID" = 'id'
}
enum NodeBaseAttrName {
    "NAME" = 'name',
    "TYPE" = 'type',
    "PARENT" = 'parent'
}
enum SignalAttrName {
    'SIGNAL' = 'signal',
    "FROM" = 'from',
    "TO" = 'to',
    "METHOD" = 'method',
}

export {
    Tscn,
    TscnExtResource,
    TscnSubResource,
    TscnNode,
    TscnSignal,

    NodeType,
    SceneAttrName,
    ExtAttrName,
    SubAttrName,
    NodeBaseAttrName,
    SignalAttrName,

    TscnProp,
    TscnAttr
}